from playwright.sync_api import sync_playwright

# with as是python的语法糖，常用在上下文环境需要关闭资源的场景，
# 类似于Java中的try-with-resources的写法
with sync_playwright() as p:
    browser = p.chromium.launch(headless=False, slow_mo=2000) # 显示启动浏览器，停顿2秒
    page = browser.new_page() # 打开一个标签页
    page.goto("https://www.baidu.com") # 打开百度地址
    print(page.title()) # 打印当前页面title
    browser.close() # 关闭浏览器